define(["moment"], function (moment) {
	return ["$scope", "$filter", "$stateParams", "config", "MMWService","$mdDialog",
	function ($scope, $filter, $stateParams, config, $MMWService,$mdDialog) {
		$scope.init = function(){
			//每隻程式都有，等於window.onload方法
			$scope.C00_require_condition = true;
			var datasource_format_info = {};
			datasource_format_info.iselectd_filed = "0";
			datasource_format_info.column_info = [$filter('translate')('B0404.list.column_1')];
            $scope.codeList = [
                {name:$filter('translate')('B0404.list.column_1'), column_name:'WOE.LOTNO'}
			];
			$scope.abnormal_lot_info = [];
			$scope.current_select_eventid = "";
		}
		
		$scope.back = function(){
            //返回首頁，傳入true表示使用退出
            $scope.$root.hideMenu();
            $scope.$root.changeProgram('home', true);//動畫
		}
		
		$scope.confirm = function(){
			//確認按鈕
			var msg = $filter('translate')('B0404.alert.note_1');
			$scope.$root.showConfirm(msg, function(confirm_dialog)
			{
				confirm_dialog.hide();
				if($filter('filter')($scope.abnormal_lot_info,{event_id:$scope.current_select_eventid}).length > 0)
				{
					var content = $filter('filter')($scope.abnormal_lot_info,{event_id:$scope.current_select_eventid})[0];
					$MMWService.sendToServer({
						uri : 'ServicesSTD.Module_WIP.rollback_abnormal_plot_process',
						content : content,
						success : function(data){
							$scope.$root.showAlert($filter('translate')('B0404.alert.note_2'));
							$scope.init();
							//$filter('translate')('A01.msg.selectArea')
						},
						error_callback:function(data)
						{

						}
					});
				}
			});
		}
		$scope.select_item = function(event,item)
		{
			if($scope.current_select_eventid == item.event_id)
				$scope.current_select_eventid = "";
			else
				$scope.current_select_eventid = item.event_id;

		}
		$scope.search = function(condition)
		{
			if(condition.length > 0)
			{
				$scope.abnormal_lot_info = [];
				$scope.current_select_eventid = "";
				var content = {};
				content.query_condition = condition;
				$MMWService.sendToServer({
                    uri : 'ServicesSTD.Module_WIP.rollback_abnormal_plot_info_get',
                    content : content,
                    success : function(data){
						if(data.plot_data && data.plot_data.length > 0)
						{
							$scope.abnormal_lot_info = data.plot_data;
						}
                    },
                    error_callback:function(data){
                      
                    }
                });
			}
			else
			{
				$scope.$root.showAlert($filter('translate')('common.msg.no_report_condition'));
			}
		}
		

	}
]});